package com.example.exp03_calculatebmi.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;

import com.example.exp03_calculatebmi.R;
import com.example.exp03_calculatebmi.data.Adult;


public class FirstActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText weightET,heightET;
    private RadioGroup genderRGP;
    private Adult adult;
    private String genter;
    private Intent intent;

    public void setGenter(String genter) {
        this.genter = genter;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        genderRGP = findViewById(R.id.genderRG);
        weightET = findViewById(R.id.weightEditText);
        heightET = findViewById(R.id.heightEditText);

        findViewById(R.id.btnResult).setOnClickListener(this);
        //      获取性别
        genderRGP.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch(i){
                    case R.id.rbBoy:
                        setGenter("男");
                        break;
                    case R.id.rbGirl:
                        setGenter("女");
                        break;
                }
            }
        });
    }

    @Override
    public void onClick(View view) {
        intent = new Intent();
        Double weight;
        Double height;
        weight = Double.valueOf(weightET.getText().toString());
        height = Double.valueOf(heightET.getText().toString());
        adult = new Adult(genter,height,weight);

//        输出测试
        Log.i("adult",adult.toString());

        intent.putExtra("info",adult);
//        显式Intent
        intent.setClass(FirstActivity.this, SecondActivity.class);
        startActivity(intent);
    }


}